<?php

namespace App\Services;
use App\Exceptions\WorkException;
use App\Services\BaseServices;
use App\Models\Admin;
use App\Util\Code;
use http\Env\Request;


class AdminServices extends BaseServices{

    /**
     * 根据用户名获取用户
     * @param $userName
     * @return Admin|null|Model|object
     */

    public function getByUser( $userName )
    {
        return Admin::query()->where('user_name', $userName )->first();
    }
    /**
     * 根据用户id获取用户
     * @param $userName
     * @return Admin|null|Model|object
     */
    public function getByUserId( $id )
    {
        return Admin::query()->where('id', $id )->first();
    }
    /**
     * 根据手机号获取用户
     * @param $userName
     * @return Admin|null|Model|object
     */

    public function getByMobile( $mobile )
    {
        return Admin::query()->where('mobile', $mobile )->first();
    }
    /**
     * 根据用户id获取用户
     * @param $userName
     * @return Admin|null|Model|object
     */
    /**
     * 根据手机号获取用户
     * @param $userName
     * @return Admin|null|Model|object
     */
    public function getByUserMobile( $mobile )
    {
        return  Admin::query()->where('mobile', $mobile )->first();
    }
    /**
     * 获取用户列表
     * @param $userName
     * @param $columns
     * @return Admin|null|Model|object
     */
    public function listAdmins($request , $columns)
    {
        $query =  Admin::query()->where('status','0');

        $username = $request->input('username' );

        if (!empty($username) ){

            $query ->where('user_name',$username );
        }
        
        return $query->orderBy('created_at')
            ->paginate(10, $columns, 'page', $request->page);
    }
}